

function  SuperMapInit() {


    var map,local, layer, layerHarbin,vectorLayer, vectorLayer1, drawPolygon, markerLayer, drawPoint, drawLine,
        style = {
            strokeColor: "#304DBE",
            strokeWidth: 1,
            pointerEvents: "visiblePainted",
            fillColor: "#304DBE",
            fillOpacity: 0.5
        },
        url = HB_SERVER_IP,
        url1 = HB_GRID_SERVER;

    function addLayer1() {
        layerHarbin = new SuperMap.Layer.TiledDynamicRESTLayer("哈尔滨网格地图", url1, {
            transparent: true,
            cacheEnabled: true
        });
        layerHarbin.events.on({
            "layerInitialized": addLayer2
        });
    }
    function addLayer2() {
        map.addLayers([layer,layerHarbin, vectorLayer, vectorLayer1, markerLayer]);
        map.setCenter(new SuperMap.LonLat(14099892, 5712596), 10);
    }

    $(function () {
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer1});
        vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
        vectorLayer1 = new SuperMap.Layer.Vector("Vector Layer1");
        markerLayer = new SuperMap.Layer.Markers("Markers");

        //点查询
        drawPoint = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point);
        drawPoint.events.on({"featureadded": drawPointCompleted});

        map = new SuperMap.Map("map", {
            controls: [
//            new SuperMap.Control.LayerSwitcher(),
//            new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                }),
                drawPoint,
            ]
        });
        drawPoint.activate();
//        map.events.on({
//            "click": mouseClick
//        }); //添加click事件
////
    })

//    function mouseClick(e) {
//        drawPoint.activate();
//        var lonlat = map.getLonLatFromPixel(new SuperMap.Pixel(e.xy.x, e.xy.y));
////        alert("位置坐标:" + lonlat.lon.toFixed(5) + "       " + lonlat.lat.toFixed(5));
////        document.getElementById("lng").value = lonlat.lon.toFixed(5);
////        document.getElementById("lat").value = lonlat.lat.toFixed(5);
////        clearStatus();
//
//    }

    function processCompleted(queryEventArgs) {
//        console.log(queryEventArgs);
        drawPoint.deactivate();
        var i, j, result = queryEventArgs.result;
        if (result && result.recordsets) {
            for (i = 0, recordsets = result.recordsets, len = recordsets.length; i < len; i++) {
                if (recordsets[i].features) {
                    for (j = 0; j < recordsets[i].features.length; j++) {
                        var feature = recordsets[i].features[j];
//                        alert(feature.attributes.SmID);

                        var   SmID = feature.attributes.SmID;
                        //alert(SmID);
                        AjaxQueryGridName(SmID);

                    }
                }
            }
        }
    }

   function clearStatus() {
       vectorLayer.removeAllFeatures();
       vectorLayer1.removeAllFeatures();
       markerLayer.clearMarkers();
   }


    function drawPointCompleted(drawGeometryArgs) {

        document.getElementById("lng").value=drawGeometryArgs.feature.geometry.x;
        document.getElementById("lat").value=drawGeometryArgs.feature.geometry.y;

        var feature = new SuperMap.Feature.Vector();
        feature.geometry = drawGeometryArgs.feature.geometry,
            feature.style = style;
        vectorLayer.addFeatures(feature);

        var queryParam, queryByGeometryParameters, queryService;
        queryParam = new SuperMap.REST.FilterParameter({name: "BuildRegion_habin@China.1"});
        queryByGeometryParameters = new SuperMap.REST.QueryByGeometryParameters({
            queryParams: [queryParam],
            geometry: drawGeometryArgs.feature.geometry,
            spatialQueryMode: SuperMap.REST.SpatialQueryMode.INTERSECT
        });
        queryService = new SuperMap.REST.QueryByGeometryService(url1, {
            eventListeners: {
                "processCompleted": processCompleted,
                "processFailed": processFailed
            }
        });
        queryService.processAsync(queryByGeometryParameters);
    }



   function processFailed(e) {
       alert(e.error.errorMsg);
   }

    //根据小网格ID查询责任网格
    function  AjaxQueryGridName(smid){
        $.getJSON('eventData/queryGridName',{'smid':smid} ,function (result) {

            $("#cellGridId").val(smid);
            $("#gridName").val(result.name);
        });
        drawPoint.activate();

    }


}









  

